/****************************************************************
 *
 *  Add some comments here
 * 
 * 
 * 
 * 
 ***************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace Wicresoft.OmsClient
{
    class ReminderGetter
    {
        public static reminderDataReminder[] GetReminders()
        {
            if (grfo == null)
                return null;
            List<reminderDataReminder> list = new List<reminderDataReminder>();
            Outlook.Reminders rs = grfo();
            if (rs != null)
            {
                foreach (Outlook.Reminder var in rs)
                {
                    try
                    {
                        reminderDataReminder rdr = new reminderDataReminder();
                        rdr.ReminderTime = Convert.ToDecimal(var.NextReminderDate.ToOADate());

                        if (var.Item is Outlook.AppointmentItem)
                        {
                            Outlook.AppointmentItem item = (Outlook.AppointmentItem)var.Item;
                            rdr.EntryID = item.EntryID;
                            rdr.Content = "Subject: " + item.Subject;
                            rdr.Content += item.Location != null ? ", Location: " + item.Location : string.Empty;
                            
                            rdr.StartTime = Convert.ToDecimal(item.Start.ToOADate());
                            rdr.EndTime = Convert.ToDecimal(item.End.ToOADate());
                        }
                        else if (var.Item is Outlook.MeetingItem)
                        {
                            Outlook.MeetingItem item = (Outlook.MeetingItem)var.Item;
                            rdr.EntryID = item.EntryID;
                            rdr.Content = "Subject: " + item.Subject;
                        }
                        else if (var.Item is Outlook.TaskItem)
                        {
                            Outlook.TaskItem item = (Outlook.TaskItem)var.Item;
                            rdr.EntryID = item.EntryID;
                            rdr.Content = "Subject: " + item.Subject;
                        }
                        else
                        {
                            continue;
                        }
                        list.Add(rdr);
                    }
                    catch (Exception ex)
                    {
                        Logger.Exception("ReminderGetter.GetReminders ", ex);
                    }                   
                }
            }
            return list.ToArray();
        }

        private static GetReminderFromOutlook grfo;

        public static GetReminderFromOutlook Grfo
        {
            get
            {
                return ReminderGetter.grfo;
            }
            set
            {
                ReminderGetter.grfo = value;
            }
        }
    }

    public delegate Outlook.Reminders GetReminderFromOutlook();
}
